package com.example.webapp.controler;

import com.example.webapp.bean.User;
import com.example.webapp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class LoginControler {
    @Autowired
    private UserService userService;

    @CrossOrigin
    @PostMapping("/login")
    @ResponseBody
    public String login(@RequestBody Map map){
        System.out.println(map.get("username") + " , " + map.get("password"));
        String usr=(String)map.get("username");
        String pwd=(String)map.get("password");
        User res=userService.selectUsernameAndPassword(usr,pwd);
        if(res==null){
            return "nouser";
        }else{
            return  res.Serialization();
        }
    }
}
